package com.mysterymall.Controller;

import com.mysterymall.Common.Comp.HttpStatus;
import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Model.Dto.SelectGoodsDto;
import com.mysterymall.Service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName com.mysterymall.Controller
 * @Description
 * @Author HuangWX
 * @Time 2023/11/04  00:33
 */
@RestController
@RequestMapping("/goods")
public class GoodsCont {


    private final GoodsService goodsService;

    /**
     * 构造器注入
     * @param goodsService 商品服务
     */
    public GoodsCont(GoodsService goodsService) {
        this.goodsService = goodsService;
    }

    /**
     * 查询所有商品
     * @param page  页码
     * @return Result
     */
    @GetMapping("/getShopList")
    @Log
    public Result getShopList(@RequestParam("page")Integer page,HttpServletRequest request){

        if(page <= 0){
            return new Result(HttpStatus.BAD_REQUEST,"message.ParameterError");
        }
        return goodsService.getShopList(page,request);
    }


    /**
     * 查询商品详情
     * @param goodsId 商品id
     * @return Result
     */
    @GetMapping("/getShopGoodsMonomer")
    @Log
    public Result getShopGoodsMonomer(@RequestParam("goodsId")String goodsId, HttpServletRequest request){

        if("".equals(goodsId)){
            return new Result(HttpStatus.BAD_REQUEST,"message.ParameterError");
        }
        return goodsService.getShopGoodsMonomer(goodsId,request);
    }


    /**
     * 根据商品类别ID查询商品
     * @param selectGoodsDto 查询条件
     * @return Result
     */
    @PostMapping("/getGoodsTypeGoodsList")
    @Log
    public Result getGoodsTypeGoodsList(@RequestBody SelectGoodsDto selectGoodsDto, HttpServletRequest request){
        return goodsService.getGoodsTypeGoodsList(selectGoodsDto,request);
    }


    /**
     * 根据商品类别查询我的商品  (全部商品,已兑换商品)
     * @param type 商品类别ID
     * @return Result
     */
    @GetMapping("/getMyUserGoods")
    @Log
    public Result getMyUserGoods(@RequestParam("type")String type, HttpServletRequest request,
                                 @RequestParam(value = "page",required = false)Integer page,
                                 @RequestParam(value = "pageSize",required = false)Integer pageSize){
        return goodsService.getMyUserGoods(type,request,page,pageSize);
    }


    /**
     * 商品兑换
     * @param goodsId 用户商品ID
     * @return Result
     */
    @GetMapping("/goodsExchange")
    @Log
    public Result goodsExchange(@RequestParam("goodsId")String goodsId){
        return goodsService.goodsExchange(goodsId);
    }

}
